"""
# Definition for a Node.
"""
import collections
class Node(object):
    def __init__(self, val, children):
        self.val = val
        self.children = children



class Solution(object):
    def preorder(self, root):
        """
        :type root: Node
        :rtype: List[int]
        """
        if not root:
            return []
        res, stack = [], [root]
        while stack:
            node = stack.pop()
            res.append(node.val)
            for child in node.children[::-1]:
                stack.append(child)
        return res









            # if not root:
            #     return []
            # a = []
            # a.append(root.val)
            # for child in root.children:
            #     a += self.preorder(child)
            # return a
